/*
 * Copyright (C) 2012, Nils Asmussen <nils@os.inf.tu-dresden.de>
 * Economic rights: Technische Universitaet Dresden (Germany)
 *
 * This file is part of NRE (NOVA runtime environment).
 *
 * NRE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * NRE is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License version 2 for more details.
 */

#pragma once

namespace nre {

/**
 * Empty lock-policy that does nothing
 */
class LockPolicyNone {
public:
    explicit LockPolicyNone() {
    }
    virtual ~LockPolicyNone() {
    }
    void lock() {
    }
    void unlock() {
    }

private:
    LockPolicyNone(const LockPolicyNone&);
    LockPolicyNone& operator=(const LockPolicyNone&);
};

/**
 * A lock policy that takes an arbitrary lock-class and expects an up() and down() method.
 */
template<class T>
class LockPolicyDefault {
public:
    explicit LockPolicyDefault() : _l() {
    }
    virtual ~LockPolicyDefault() {
    }
    void lock() {
        _l.down();
    }
    void unlock() {
        _l.up();
    }

private:
    LockPolicyDefault(const LockPolicyDefault<T>&);
    LockPolicyDefault<T>& operator=(const LockPolicyDefault<T>&);

private:
    T _l;
};

}
